package org.example.common.utils;

import java.util.HashMap;

public class RedisSession {
    private final HashMap<Object, Object> hashMap = new HashMap<>();

    public void put(String key,Object object){
        hashMap.put(key,object);
    }

    public <T> T get(String key,Class<T> cls) throws NoSuchMethodException,NullPointerException {
        Object object = hashMap.get(key);
        // 如果对象不为空，且符合指定的类型，则进行类型转换并返回
        if (cls.isInstance(object)) {
            return cls.cast(object);
        } else
            // 如果对象为空，则抛出 NullPointerException 异常
            throw new NullPointerException("No object found for the key: " + key);
    }
}
